#!/usr/bin/env python
# Author: 

PKG = 'circle_detector'

# All ROS python nodes should have these lines
import roslib; roslib.load_manifest(PKG)
import rospy

import cv


#original_c = cv.LoadImage("/home/robotlab/Desktop/rawimages/box2.jpg") #,cv.CV_LOAD_IMAGE_GRAYSCALE)
original_gs = cv.LoadImage("/home/robotlab/Desktop/rawimages/filtered.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
#print original.width, original.height

#cv.Threshold(original_gs, original_gs , 1, 255, cv.CV_THRESH_BINARY)

seq = cv.FindContours(original_gs, cv.CreateMemStorage(), cv.CV_RETR_EXTERNAL, cv.CV_CHAIN_APPROX_SIMPLE)
print len(seq)
for x in seq:
   print x

#cv.SaveImage("/home/robotlab/Desktop/rawimages/out.jpg", original_gs)

cv.DrawContours(original_c, seq, cv.RGB(255, 0, 0), cv.RGB(0, 255, 0),0, 1, 8, (0, 0))
cv.SaveImage("/home/robotlab/Desktop/rawimages/out.jpg", original_gs)
